package com.example.blogserver.controller;

import com.example.blogserver.service.LoginService;
import com.example.blogserver.a_utils.ResponseBodyMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings({"all"})
@RestController
@RequestMapping("/login")
public class LoginController {
    @Autowired
    private LoginService loginService;

    /**
     * 处理登录请求
     */
    @RequestMapping("/sub")
    public ResponseBodyMessage<Boolean> login(HttpServletRequest request,
                                              @RequestParam String account,
                                              @RequestParam String password,
                                              @RequestParam String verifyCode) {
        return loginService.checkOut(request, account, password, verifyCode);
    }

    /**
     * 生成图文验证码
     */
    @RequestMapping("/verifyCode")
    public void generateImage(HttpServletRequest request, HttpServletResponse response){
        loginService.buildCheckImage(request,response);
    }

    /**
     * 退出登录请求
     */
    @RequestMapping("/out")
    public ResponseBodyMessage<Boolean> loginOut(HttpServletRequest request){
        return loginService.loginOut(request);
    }
}
